<?php

declare(strict_types=1);

namespace App\Chat\Support;

use App\Chat\Amqp\Producers\WebSocketProducer;
use App\Chat\Constant\RedisSubscribeChan;
use Hyperf\Amqp\Producer;

class Message
{
    /**
     * @param string $event
     * @param array  $data
     * @param array  $options
     * @return array
     */
    public static function create(string $event, array $data, array $options = []): array
    {
        return [
            'uuid'    => uniqid((strval(mt_rand(0, 1000)))),
            'event'   => $event,
            'data'    => $data,
            'options' => $options
        ];
    }

    /**
     * 推送消息至 Redis 订阅通道中
     *
     * @param array $message
     */
    public static function publish(array $message)
    {
        push_redis_subscribe(RedisSubscribeChan::WEBSOCKET_CHAN, $message);
//        $producer = di()->get(Producer::class);
//        $amqpMessage = new WebSocketProducer($message);
//
//        try {
//            $result = $producer->produce($amqpMessage);
//            stdout_log()->info('推送消息到 RabbitMQ：' . ($result ? '成功' : '失败'));
//        } catch (\Throwable $e) {
//            stdout_log()->error('RabbitMQ 推送失败: ' . $e->getMessage());
//        }
    }
}